package com.ewzj.bigdata.mvp.ui.activity

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide

import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.config.AppKey
import com.ewzj.bigdata.app.utils.Apputils
import com.ewzj.bigdata.di.component.DaggerSettingActivityComponent
import com.ewzj.bigdata.di.module.SettingActivityModule
import com.ewzj.bigdata.mvp.contract.SettingActivityContract
import com.ewzj.bigdata.mvp.presenter.SettingActivityPresenter
import com.jakewharton.rxbinding2.view.RxView
import com.jess.arms.base.BaseActivity
import com.jess.arms.di.component.AppComponent
import com.jess.arms.utils.DataHelper
import com.jess.arms.widget.CustomPopupWindow
import io.rx_cache2.internal.RxCache
import kotlinx.android.synthetic.main.activity_setting.*
import kotlinx.android.synthetic.main.titile_red.*
import javax.inject.Inject

class SettingActivity : BaseActivity<SettingActivityPresenter>(), SettingActivityContract.View {
    val customPopupWindow by lazy {
        CustomPopupWindow.builder().parentView(tv_cache).contentView(View.inflate(this, R.layout.popwindow_delconfirm, null)).isWrap(true).customListener { contentView ->
            initpopwindowListener(contentView)
        }.build()
    }
    private fun initpopwindowListener(contentView: View) {
        RxView.clicks(contentView.findViewById(R.id.tv_confirm)).subscribe({
            customPopupWindow.dismiss()
            mPresenter.deleteCache()
        })
        RxView.clicks(contentView.findViewById(R.id.tv_cancel)).subscribe({ customPopupWindow.dismiss() })
    }

    override fun initData(savedInstanceState: Bundle?) {
        if (Apputils.Utils.checkIsLogin(this)) {
            tv_loginuot.setVisibility(View.VISIBLE)
        } else {
            tv_loginuot.setVisibility(View.GONE)
        }
        tv_title.text = "设置"
        RxView.clicks(iv_back).subscribe({ finish() })
        RxView.clicks(tv_loginuot).subscribe({
            DataHelper.SetStringSF(this, AppKey.API_TOKEN, "")
            finish()
        })
        RxView.clicks(layout_clean_cache).subscribe({ customPopupWindow.show() })
        mPresenter.getCacacheFileSize()
    }

    override fun setupActivityComponent(appComponent: AppComponent?) {
        DaggerSettingActivityComponent.builder().appComponent(appComponent)
                .settingActivityModule(SettingActivityModule(this))
                .build().inject(this)
    }

    override fun initView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_setting
    }

    override fun showConfirmWindow() {
    }

    override fun setCacheSize(size: String) {
        tv_cache.text = size
    }

    override fun showLoading() {
    }

    override fun launchActivity(intent: Intent?) {
    }

    override fun hideLoading() {
    }

    override fun killMyself() {
    }

    override fun showMessage(message: String?) {
    }


}
